<template>
  <div>
    <!-- 整个页面 -->
    <el-container>
      <!-- 顶部 -->
      <el-header class="layout-header">
        <div style="text-align: center">
        <h1>易购商城运营管理平台
          <span style="float: right; margin-left: 10px"><a href="javascript:void(0)" @click="logout()">退出</a></span>
          <el-avatar style="float: right;margin-left: 10px;margin-top: 10px" :src="require('D:/files/'+admin.avatar)"></el-avatar>
          <span style="float: right;  margin-left: 10px">欢迎<span style="color: #222c32; font-weight: bold">{{admin.nickname}}</span>回来!</span>
        </h1>
        </div>
      </el-header>
      <!-- 下半部分 -->
      <el-container class="layout-body">
        <!-- 下半部分的左侧边栏 -->
        <el-aside class="layout-aside">
          <el-menu
              router
              :default-active="this.$router.currentRoute.path"
              class="el-menu-vertical-demo"
              background-color="#222c32"
              text-color="#fff"
              active-text-color="#fff">
            <el-menu-item>
              <i class="el-icon-s-home"></i>
              <span slot="title">首页</span>
            </el-menu-item>
            <el-submenu index="1">
              <template slot="title">
                <i class="el-icon-s-tools"></i>
                <span>品牌管理</span>
              </template>
              <el-menu-item index="/sys-admin/temp/brand/add-new">
                <i class="el-icon-circle-plus"></i>
                <span slot="title">添加品牌</span>
              </el-menu-item>
              <el-menu-item index="/sys-admin/temp/brand/list">
                <i class="el-icon-s-operation"></i>
                <span slot="title">品牌列表</span>
              </el-menu-item>
            </el-submenu>

            <el-submenu index="2">
              <template slot="title">
                <i class="el-icon-s-tools"></i>
                <span>手机系列管理</span>
              </template>
              <el-menu-item index="/sys-admin/temp/series/add-new">
                <i class="el-icon-circle-plus"></i>
                <span slot="title">添加手机系列</span>
              </el-menu-item>
              <el-menu-item index="/sys-admin/temp/series/list">
                <i class="el-icon-s-operation"></i>
                <span slot="title">手机系列列表</span>
              </el-menu-item>
            </el-submenu>

            <el-submenu index="3">
              <template slot="title">
                <i class="el-icon-s-tools"></i>
                <span>订单管理</span>
              </template>
              <el-menu-item index="/sys-admin/temp/order/list">
                <i class="el-icon-s-operation"></i>
                <span slot="title">订单列表</span>
              </el-menu-item>
            </el-submenu>

            <el-submenu index="4">
              <template slot="title">
                <i class="el-icon-s-tools"></i>
                <span>轮播图管理</span>
              </template>
              <el-menu-item index="/sys-admin/temp/banner/add-new">
                <i class="el-icon-circle-plus"></i>
                <span slot="title">添加轮播图</span>
              </el-menu-item>
              <el-menu-item index="/sys-admin/temp/banner/list">
                <i class="el-icon-s-operation"></i>
                <span slot="title">轮播图列表</span>
              </el-menu-item>
            </el-submenu>

            <el-submenu index="5">
              <template slot="title">
                <i class="el-icon-s-tools"></i>
                <span>商品管理</span>
              </template>
              <el-menu-item index="/sys-admin/temp/phone/add-new">
                <i class="el-icon-circle-plus"></i>
                <span slot="title">添加商品</span>
              </el-menu-item>
              <el-menu-item index="/sys-admin/temp/phone/list">
                <i class="el-icon-s-operation"></i>
                <span slot="title">商品列表</span>
              </el-menu-item>
            </el-submenu>

            <el-submenu index="6">
              <template slot="title">
                <i class="el-icon-s-tools"></i>
                <span>手机配置管理</span>
              </template>
              <el-menu-item index="/sys-admin/temp/detail/add-new">
                <i class="el-icon-circle-plus"></i>
                <span slot="title">添加手机配置</span>
              </el-menu-item>
              <el-menu-item index="/sys-admin/temp/detail/list">
                <i class="el-icon-s-operation"></i>
                <span slot="title">手机配置列表</span>
              </el-menu-item>
            </el-submenu>

            <el-submenu index="7">
              <template slot="title">
                <i class="el-icon-s-tools"></i>
                <span>手机配色管理</span>
              </template>
              <el-menu-item index="/sys-admin/temp/color/add-new">
                <i class="el-icon-circle-plus"></i>
                <span slot="title">添加手机配色</span>
              </el-menu-item>
              <el-menu-item index="/sys-admin/temp/color/list">
                <i class="el-icon-s-operation"></i>
                <span slot="title">手机配色列表</span>
              </el-menu-item>
            </el-submenu>

            <el-submenu index="8">
              <template slot="title">
                <i class="el-icon-s-tools"></i>
                <span>管理员管理</span>
              </template>
              <el-menu-item index="/sys-admin/temp/admin/add-new">
                <i class="el-icon-circle-plus"></i>
                <span slot="title">添加管理员</span>
              </el-menu-item>
              <el-menu-item index="/sys-admin/temp/admin/list">
                <i class="el-icon-s-operation"></i>
                <span slot="title">管理员列表</span>
              </el-menu-item>
            </el-submenu>

            <el-submenu index="9">
              <template slot="title">
                <i class="el-icon-s-tools"></i>
                <span>用户管理</span>
              </template>
              <el-menu-item index="/sys-admin/temp/user/list">
                <i class="el-icon-s-operation"></i>
                <span slot="title">用户列表</span>
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <!-- 下半部分的右侧主体 -->
        <el-main>
          <!-- 将由其它视图组件显示右侧的主体部分 -->
          <router-view/>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  data: function () {
    return {//在这里面定义变量
      admin:[]
    }
  },
  mounted() {
    //发请求获取当前登录管理员对象
    let url='http://localhost:1011/admins/showUser'
    this.axios
        .create({'headers': {'Authorization': localStorage.getItem('jwt')}})
        .post(url).then((res) =>{
    this.admin = res.data.data;
    //判断是否登录
      if(this.admin==""){
        alert("请先登录！")
        location.href="/admin";
      }
    })

  },
  methods:{
    logout() {
      if (confirm("您确认退出登录吗?")) {
        localStorage.removeItem("jwt");
        location.href = "/admin";//回到首页
      }
    }
  }
}

</script>

<style>
body {
  background-color: #fff !important;
}


.layout-header {
  background: #1684b0;
  line-height: 60px;
  font-size: 16px;
  color: #fff;
}

.layout-body {
  position: absolute;
  top: 60px;
  bottom: 0;
  left: 0;
  right: 0;
}

.layout-aside {
  background: #222c32;
}

.layout-aside i {
  color: #fff;
}

.el-menu-item.is-active {
  background-color: #2d3c4d !important;
}
</style>